import React, { useEffect, useState } from 'react';
import $http from 'api';
import { Table } from 'antd';
import { columnData } from './renderType';

function RecordTable({ type, interfaceName, requestData }) {
  const [source, setSource] = useState([]);
  const [total, setTotal] = useState(0);
  useEffect(() => {
    _initData();
  }, []);

  const _initData = async () => {
    const res = await $http[interfaceName]({ ...requestData });
    setSource(res.data?.list);
    setTotal(res.data?.total);
  };
  const changePage = () => {
    _initData(page);
  };
  return (
    <Table
      pagination={{ defaultPageSize: 5, onChange: changePage, total }}
      columns={columnData[type]}
      rowKey={(columns) => columns._id}
      dataSource={source}
    ></Table>
  );
}

export default RecordTable;
